package com.endurance.filter;

import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Author: sunlin
 * @Date: 2024-04-21 2:25
 * @Version: 1.0
 * @Description: 自定义的过滤器
 */
    @Component
    public class MultValueGatewayFilterFactory extends AbstractNameValueGatewayFilterFactory {

        @Override
        public GatewayFilter apply(NameValueConfig config) {
            return new GatewayFilter() {
                @Override
                public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
                    String name = config.getName();
                    String value = config.getValue();
                    System.out.println("name:" + name);
                    System.out.println("value:" + value);
                    return chain.filter(exchange);
                }
            };
        }
    }
